clear all
set memo 100m
capture log close

local filename Sector

log using Sector, replace text

local output_dir draft
local output_tex1 `filename'.tex

cd "C:\Users\rujia\Dropbox\Replication\treatyports"


use "data\GDP.dta", clear

merge  m:1 id using data\subgroup.dta
**Wuchang should be counted as a treaty port in the modern period.
replace treatyport=1 if id==37

gen agr_per=gdp_per_-tindustryper-ind_per
replace gdp_per=. if agr_per==.
replace ind_per=. if agr_per==.
replace tindustryper=. if agr_per==.
sum agr_per ind_per gdp_per

gen ln_agrper=log(agr_per)

gen ln_ind_per=log(ind_per)
gen ln_tindustryper=log(tindustryper)

qui tabu year, gen(ydummy)
qui tabu id, gen(idummy)

gen d1987_treaty=treatyports*ydummy1

gen d1990_treaty=treatyports*ydummy2
gen d1995_treaty=treatyports*ydummy3
gen d2000_treaty=treatyports*ydummy4
gen d2005_treaty=treatyports*ydummy5
gen d2007_treaty=treatyports*ydummy6

label var  d1990_treaty "Treatyport*Year1990"
label var  d1995_treaty  "Treatyport*Year1995"
label var d2000_treaty  "Treatyport*Year2000"
label var d2005_treaty  "Treatyport*Year2005"
label var  d2007_treaty  "Treatyport*Year2007"


local fe "idummy* ydummy*"
#delimit ;
eststo clear;

eststo:  regress  ln_agrper d1990_treaty d1995_treaty d2000_treaty d2005_treaty d2007_treaty `fe', cluster (id);
estadd local fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);


eststo:  regress ln_ind_per d1990_treaty d1995_treaty d2000_treaty d2005_treaty d2007_treaty `fe', cluster (id);
estadd local fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);


eststo:  regress ln_tindustryper d1990_treaty d1995_treaty d2000_treaty d2005_treaty d2007_treaty `fe', cluster (id);
estadd local fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);


eststo:  regress  agr_per d1990_treaty d1995_treaty d2000_treaty d2005_treaty d2007_treaty `fe', cluster (id);
estadd local fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);


eststo:  regress ind_per d1990_treaty d1995_treaty d2000_treaty d2005_treaty d2007_treaty `fe', cluster (id);
estadd local fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);


eststo:  regress tindustryper d1990_treaty d1995_treaty d2000_treaty d2005_treaty d2007_treaty `fe', cluster (id);
estadd local fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);

esttab using draft/`output_tex1', replace
	width(\hsize) 
	mlabel (, depvar)
	b(3)
	se(3)
	noconstant
	star(* 0.10 ** 0.05 *** 0.01)
	keep(
d1990_treaty 
d1995_treaty 
d2000_treaty 
d2005_treaty 
d2007_treaty
		)
		
	label
	stats(
		fe
		control_fe
		 nobs
		 rsquare
		, 
		labels(
			"Prefecture and Year FE" 
			"Controls*Year FE" 
			"\# observations"
			"R-squared"
			) 
		fmt(0)
		layout(@)
		)
	nonotes
	;
